home *** CD-ROM | disk | FTP | other *** search
- Path: eua.ericsson.se!usenet
- From: euahjn@eua.ericsson.se (Henrik Johansson)
- Newsgroups: comp.lang.c++
- Subject: Re: Are Pure Functions always Virtual????
- Date: 5 Jan 1996 11:18:43 GMT
- Organization: Ericsson Telecom Systems Labs, Stockholm, Sweden
- Message-ID: <4cj1ej$ifu@euas20.eua.ericsson.se>
- References: <4cilse$5li@news2.deltanet.com>
- Reply-To: euahjn@eua.ericsson.se
- NNTP-Posting-Host: euas31i2c37.eua.ericsson.se
-
- In article <4cilse$5li@news2.deltanet.com>, olivas@deltanet.com (Sergio Olivas) writes:
- >
- > I have a base class for accessing databases (BC++), the base class is
- > made of only pure virtual functions. Two derived classes are written,
- > one for accessing databases through the Paradox Engine, the other
- > using the Borland Database Engine.
- >
- > Since I've heard that using virtual functions really eats into the 64k
- > automatic data segment, as well as adding overhead, is the 'virtual'
- > keyword really needed. -- and does it make any difference, assuming
- > I'm not going to further derive another class from the newly derived
- > class (in this case DB_BASE_PDX) ???
- >
- > eg..
- > class DB_BASE {
- > { ...
- > virtual int NextRecord(int TableID) = 0;
- > ..^^^^^ is this needed?
- > };
- >
- > The derived classes are something like
- > class DB_BASE_PDX : public DB_BASE
- > {
- > ...
- > int NextRecord(int TableID);
- > ...
- > }
-
- If you only have 2 known subclasses, and doesn't want to use virtual fns,
- then the alternative is to invoke the formerly virtual, now statically bound
- fn by using RunTime Type Identification (RTTI) combined with if-else construction
- and downcasting with (DB_BASE_PDX)*. This allows the compiler to inline
- the function and reduces overhead and memory access. Hide the invocation
- in a preprocessor macro, like
- #define NEXTRECORD(THIS,TableID) \
- if (...) ((DB_BASE_PDX*)THIS)->NextRecord(TableID); \
- else ...
-
-